#include <stdio.h>
#include <stdlib.h>
#include "sorts.h"
 
#define SWAP(T,a,b)  {T t=a; a=b; b=t; } 
 
void select_sort(ELE_TYPE arr[], int len)
{
	int i,j;
	for ( i=0;i<len;i++)
	{
		int min=i;
		for (j=i+1;j<len;j++)
		{
			if (arr[j] < arr[min] )
				min=j;
		}
 
		if ( i!= min)
			SWAP(ELE_TYPE, arr[i],arr[min])	// call macro SWAP
	}
}
 
void test_select_sort()
{
	ELE_TYPE arr[] = { 61, 17, 29, 22, 34, 60, 72, 21, 50, 1, 62 };
	int len = (int) sizeof(arr) / sizeof(arr[0]);
	
 
	printf("Original data are:");
	print_array(arr, len);
 
	select_sort(arr, len);
	printf("The data after sorted are:");
	print_array(arr, len);	
	
}
